﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Xml;

namespace repliback4.Xml.Extensions {
    public static class XmlExtensions {
        public static XmlNode FirstTypedChild ( this XmlElement element, XmlNodeType type ) {
            if ( element.HasChildNodes ) {
                XmlNode ret = element.FirstChild;

                while(ret!=null){
                    if ( ret.NodeType == type ) { return ret; }
                    ret = ret.NextSibling;
                }
                return null;
                
            } else {
                return null;
            }
        }
        public static XmlNode LastTypedChild ( this XmlElement element, XmlNodeType type ) {
            if ( element.HasChildNodes ) {
                XmlNode ret = element.LastChild;

                while ( ret != null ) {
                    if ( ret.NodeType == type ) { return ret; }
                    ret = ret.PreviousSibling;
                }
                return null;

            } else {
                return null;
            }
        }

        public static XmlQualifiedName XmlQualifiedName ( this XmlNode node ) {
            return new XmlQualifiedName( node.Name, node.NamespaceURI );
        }
    }
}
